﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class TextSlideForm : ItemFormTemplate
    {
        public TextSlideForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件\\TextSlideForm\\TextSlideForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();

            if (this.ViewVisible)
            {
                this.demo_control.Enabled = true;
            }
        }

        public override void ShowView()
        {
            base.ShowView();

            if (this.ViewStatus > ItemFormTemplateStatus.Create && this.ViewStatus < ItemFormTemplateStatus.Closed)
            {
                this.demo_control.Enabled = true;
            }
        }

        public override void HideView()
        {
            base.HideView();

            this.demo_control.Enabled = false;
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.Text = "唧唧复唧唧，木兰当户织。不闻机杼声，唯闻女叹息。";
            this.demo_control.TextOrientation = TextSlideOrientation.RightToLeft;
            this.demo_control.TextVelocity = 1;

            this.textOrientation_dropDownListPlus.Multiple = false;
            this.textOrientation_dropDownListPlus.BindEnumList<TextSlideOrientation>(this.demo_control.TextOrientation);
            this.textOrientation_dropDownListPlus.SelectedItemsChanged += this.TextOrientation_dropDownListPlus_SelectedItemsChanged;

            this.textVelocity_label.Text = this.demo_control.TextVelocity.ToString();
            this.textVelocity_trackBarPlus.Value = this.demo_control.TextVelocity;
            this.textVelocity_trackBarPlus.ValueChanged += this.TextVelocity_trackBarPlus_ValueChanged;

        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void TextOrientation_dropDownListPlus_SelectedItemsChanged(object sender, EventArgs e)
        {
            DropDownListPlus control = (DropDownListPlus)sender;
            this.demo_control.TextOrientation = (TextSlideOrientation)control.SelectedItem.Tag;
        }

        private void TextVelocity_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.TextVelocity = (int)control.Value;
            this.textVelocity_label.Text = this.demo_control.TextVelocity.ToString();
        }

        #endregion

    }
}
